/** ***************************************************************************** **
 *    NOTE:                                                                        *
 *    see http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=43 for details    *
 ** ***************************************************************************** **/

#ifndef UGLFontH
#define UGLFontH
#include "stdafx.h"
// FreeType Headers
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#include <ft2build.h>
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
#include <freetype/ftoutln.h>
#include <freetype/fttrigon.h>

#include <string>
#include <map>

#define ellipsis "..."

typedef enum {
	TP_Left		= 1<<0,
	TP_Right	= 1<<1,
	TP_HCenter	= 1<<2,
} HTextParams;

typedef enum {
	TP_Top		= 1<<0,
	TP_Bottom	= 1<<1,
	TP_VCenter	= 1<<2,
} VTextParams;


using namespace std;

using std::vector;
using std::string;

class TGLFont;

typedef boost::shared_ptr<TGLFont> TGLFontSharedRef;
typedef boost::weak_ptr<TGLFont> TGLFontWeakRef;

class TGLFontRef
{
	private:
		TGLFontSharedRef internal_reference;
	public:
		TGLFont* operator->() {
			return internal_reference.operator->();
		}
		TGLFontRef(std::string name = "", uint size = 9, uint32 attrs = 0);
};

class TGLFont {
	friend class TGLFontRef;
	private:
		int CharWidths[256];
		inline int next_power_of_2 (int a );
		void make_dlist ( FT_Face face, uint8 ch, GLuint list_base, GLuint * tex_base );
		void create(const char * fname, unsigned int h);
		inline void pushScreenCoordinateMatrix();
		inline void pop_projection_matrix();
		float height;				// Holds The Height Of The Font.
		GLuint textures[128];	// Holds The Texture Id's
		GLuint list_base;		// Holds The First Display List Id
		int EllipsisWidth;
		TGLFont(const char * fname, uint h, uint32 attrs);

	public:
		float Height();
		int getCharWidth(const uint8 chr);
		int TextWidth(const string& Text);
		void drawText(const int x, const int y, const char* text);
		void drawText(const int x, const int y, const string& text);
		void drawText(const TRectangle& Rect, const HTextParams& HParams, const VTextParams& VParams, const char *text);
		
		int GetEllipsisWidth(){return EllipsisWidth;};
		int GetCharWidth(int index){return CharWidths[index];};  
		GLuint Getlist_base(){return list_base;};
		~TGLFont();
	};

extern std::string ClipBoard;
 

#endif
